package com.clickpaas.materialsprocurement.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component;

@Component
public class JsonUtil {

    public static JSONObject jsonStrToJson(String data) {

        if (data != null) {
            try {
                return JSON.parseObject(data);
            } catch (Exception ignored) {
            }
        }
        return null;
    }

    public static JSONObject objToJson(Object data) {

        if (data != null) {
            try {
                String s = JSON.toJSONString(data);
                return JSON.parseObject(s);
            } catch (Exception ignored) {
            }
        }
        return null;
    }
}
